<?php
final class LanguageModel {
	private $mysql;
	private $tableName = 'Language';
	public $idRowName = 'Language_ID';
	public $nameRowName = 'Language_Name';
	public $codeRowName = 'Language_Code';
	public $CountRowName = 'Language_Count';

	public function __construct ($mysql) {
		$this->mysql = $mysql;
	}

	public function GetLanguageCount () {
		$ref = 0;
		$sqlresult = $this->mysql->query (sprintf ('SELECT COUNT(*) AS `%s` FROM `%s`;', $this->mysql->escape_string ($this->CountRowName), $this->mysql->escape_string ($this->tableName)));
		$len = $sqlresult->num_rows ();
		if ($len > 0) {
			$data = $sqlresult->fetch_array ();
			$ref = $data[$this->CountRowName];
		}
		$sqlresult->free_result ();
		return $ref;
	}


	public function GetLanguageItems ($offset, $count) {
		$ref = array ();
		$sql = '';
		$sql = sprintf ('SELECT `%s`, `%s`, `%s` FROM `%s` LIMIT %d, %d;', $this->mysql->escape_string ($this->idRowName), $this->mysql->escape_string ($this->nameRowName), $this->mysql->escape_string ($this->codeRowName), $this->mysql->escape_string ($this->tableName), $this->mysql->escape_string ($offset), $this->mysql->escape_string ($count));
		$sqlresult = $this->mysql->query ($sql);
		while ($data = $sqlresult->fetch_array ()) {
			$ref[] = $data;
		}
		$sqlresult->free_result ();
		return $ref;
	}

	public function CheckLanguageExistsByID ($ID) {
		$ref = NULL;
		$sqlresult = $this->mysql->query (sprintf ('SELECT `%s`, `%s`, `%s` FROM `%s` WHERE `%s`=\'%s\';', $this->mysql->escape_string ($this->idRowName), $this->mysql->escape_string ($this->nameRowName), $this->mysql->escape_string ($this->codeRowName), $this->mysql->escape_string ($this->tableName), $this->mysql->escape_string ($this->idRowName), $this->mysql->escape_string ($ID)));
		$len = $sqlresult->affected_rows ();
		if ($len > 0) {
			$ref = $sqlresult->fetch_array ();
		}
		$sqlresult->free_result ();
		return $ref;
	}

	public function CheckLanguageExistsByCode ($Code) {
		$ref = NULL;
		$sqlresult = $this->mysql->query (sprintf ('SELECT `%s`, `%s`, `%s` FROM `%s` WHERE `%s`=\'%s\';', $this->mysql->escape_string ($this->idRowName), $this->mysql->escape_string ($this->nameRowName), $this->mysql->escape_string ($this->codeRowName), $this->mysql->escape_string ($this->tableName), $this->mysql->escape_string ($this->codeRowName), $this->mysql->escape_string ($Code)));
		$len = $sqlresult->affected_rows ();
		if ($len > 0) {
			$ref = $sqlresult->fetch_array ();
		}
		$sqlresult->free_result ();
		return $ref;
	}

}
?>